﻿using CommonServiceLocator;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Jn698._45GWTool.Services;
using Jn698._45GWTool.ViewModels.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WebFirst.Entities;

namespace Jn698._45GWTool.ViewModels
{
    public class FrameShowViewModel:ViewModelBase
    {
		private GWTempFrameService gWTempFrameService = new GWTempFrameService();
		private ObservableCollection<GWTempFrame> gWTempFrames;

		public ObservableCollection<GWTempFrame> GWTempFrames
        {
			get { return gWTempFrames; }
			set { Set(ref gWTempFrames,value); }
		}

		private int selectedIndex;

		public int SelectedIndex
        {
			get { return selectedIndex; }
			set { Set(ref selectedIndex,value); }
		}


		public FrameShowViewModel()
        {
            GWTempFrames = new ObservableCollection<GWTempFrame>(gWTempFrameService.Select());
        }

		public RelayCommand DeleteCommand
		{
			get
			{
				var command = new RelayCommand(() => 
				{
					gWTempFrameService.Delete(GWTempFrames[SelectedIndex]);
					GWTempFrames.Remove(GWTempFrames[SelectedIndex]);

                });
				return command;
			}
		}

        public RelayCommand<Window> OKCommand
        {
            get
            {
                var command = new RelayCommand<Window>((w) =>
                {
                    w.DialogResult = true;
                });
                return command;
            }
        }

        public RelayCommand<Window> CancelCommand
        {
            get
            {
                var command = new RelayCommand<Window>((w) =>
                {
                    w.DialogResult = false;
                });
                return command;
            }
        }
    }
}
